<template>
    <div class="wrapper">
        <swiper :options="swiperOption" v-if="showSwiper">
            <swiper-slide v-for="item in lists" :key="item.id">
                <img :src="item.imgUrl" class="swiper-img" alt="">
            </swiper-slide>
            <div class="swiper-pagination" slot="pagination"></div>
        </swiper>
    </div>
</template>

<script lang="ts">
    import {Vue, Component, Prop} from 'vue-property-decorator';

    @Component({
        name: 'HomeSwiper',
    })

    export default class Swiper extends Vue {
        // 给出默认值是（object / array）的方法 @Prop({type: Array, default: () => []})
        @Prop()
        private lists!: any[];

        private swiperOption: object = {
            pagination: '.swiper-pagination',
            loop: true,
        };

        get showSwiper() {
            const len = this.lists ? this.lists.length : false
            return len
        }

    }
</script>

<style lang="stylus" scoped>
    .wrapper >>> .swiper-pagination-bullet-active
        background: #fff

    .wrapper
        overflow: hidden
        width: 100%
        height: 0
        padding-bottom: 31.25%
        background: #eee

        .swiper-img
            width: 100%
</style>
